package com.upcode.weighing.common.exception;

/**
 * 支付统一抛出异常类
 * @author ZYW
 * @date 2018/5/31
 */
public class BasePayException extends RuntimeException {

    protected Integer status;
    protected String code;
    protected String message;

    public BasePayException() {
    }
    public BasePayException(ErrorType type) {
        this(type.value(),type.name(),type.msg());
    }
    public BasePayException(Integer status, String code, String message) {
        super(message);
        this.status = status;
        this.code = code;
        this.message = message;
    }

    public BasePayException(Integer status, String code, String message, Throwable cause) {
        super(message, cause);
        this.status = status;
        this.code = code;
        this.message = message;
    }

    public BasePayException(Integer status, String code, Throwable cause) {
        super(cause);
        this.status = status;
        this.code = code;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    /**
     * 记账标识:1-TAC码校验失败 9-CPU卡状态校验失败或卡在黑名单中
     */
    public static enum ErrorType {
        ETCISSUE_NO_QUERY_CONTRACT(2009,"没有查询到签约信息！"),
        ETCISSUE_NO_EXIT_TRANS_LIST(2010,"没有查询到出口交易流水！"),
        ETCISSUE_OVER_QUOTA(2011,"订单超过支付限额"),
        UPDATE_PAY_BILL(2012,"更新支付流水失败"),
        PAYMENT(2013,"订单支付中,请稍后1分钟在尝试！"),
        PAYMENT_END(2014,"没有查到账单信息,或者账单已支付！");

        private  int value;

        private  String msg;

        ErrorType(int value, String msg) {
            this.value = value;
            this.msg = msg;
        }

        public int value() {
            return value;
        }

        public String msg() {
            return msg;
        }

        //覆盖方法
        @Override
        public String toString() {
            return this.value+"_"+this.msg;
        }
        public static BasePayException.ErrorType getByValue(int value) {
            for (BasePayException.ErrorType errorType : values()) {
                if (errorType.value() == value) {
                    return errorType;
                }
            }
            return null;
        }
    }
}
